package com.qfmy.web.app.controller.conmon;

import com.qfmy.common.result.Result;
import com.qfmy.model.vo.common.BookSelfVo;
import com.qfmy.web.app.service.conmon.BookSelfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 清风明月
 * @Package com.qfmy.web.app.controller.novel
 * @date 2025/10/31
 * @description 小说书架
 */
@RestController
@RequestMapping("/app/self")
public class BookSelfController {

    /**
     * 注入服务
     */
    @Autowired
    private BookSelfService novelSelfService;

    /**
     * 添加小说
     */
    @RequestMapping("/addNovelSelf")
    public Result addNovelSelf(@RequestParam Integer novelId) {
        novelSelfService.addNovelSelf(novelId);
        return Result.ok();
    }

    /**
     * 判断是否在书架中
     */
    @RequestMapping("/isInNovelSelf")
    public Result<Boolean> isInNovelSelf(@RequestParam Integer novelId) {
        return Result.ok(novelSelfService.isInNovelSelf(novelId));
    }

    /**
     * 获取用户书架
     */
    @RequestMapping("/getNovelSelf")
    public Result<List<BookSelfVo>> getNovelSelf()
    {
        return Result.ok(novelSelfService.getNovelSelf());
    }

    /**
     * 根据书架id删除书架
     */
    @RequestMapping("/deleteNovelSelf")
    public Result<String> deleteNovelSelf(@RequestParam Integer id)
    {
        novelSelfService.deleteNovelSelf(id);
        return Result.ok("成功删除");
    }

    /**
     * 判断用户是否收藏音频
     */
    @RequestMapping("/isInAudioSelf")
    public Result<Boolean> isInAudioSelf(@RequestParam Integer audioId) {
        return Result.ok(novelSelfService.isInAudioSelf(audioId));
    }

    /**
     * 收藏音频
     */
    @RequestMapping("/addAudioSelf")
    public Result addAudioSelf(@RequestParam Integer audioId) {
        novelSelfService.addAudioSelf(audioId);
        return Result.ok();
    }

    /**
     * 根据小说id统计这个小说的收藏数
     */
    @RequestMapping("/countNovelSelf")
    public Result<Integer> countNovelSelf(@RequestParam Integer novelId) {
        return Result.ok(novelSelfService.countNovelSelf(novelId));
    }

    /**
     * 获取所有的最近删除的数据
     */
    @RequestMapping("/getAllDeleted")
    public Result<List<BookSelfVo>> getAllDeleted() {
        return Result.ok(novelSelfService.getAllDeleted());
    }

    /**
     * 找回
     * @param id
     * @return
     */
    @RequestMapping("/findNovel")
    public Result<String> findNovel(@RequestParam Integer id) {
        novelSelfService.findNovel(id);
        return Result.ok("成功找回");
    }



}
